#include<stdio.h>
#include"uthash.h"
#include<stdlib.h>
#include"use_hash.h"

void add_hash(record_t **head,record_t *p)
{
	HASH_ADD(hh,*head,key,sizeof(record_key_t),p);
}

record_t * find_hash(record_t * head,record_key_t *p)
{
	record_t *temp;
	HASH_FIND(hh,head,p,sizeof(record_key_t),temp);
	return temp;
}

void delete_hash(record_t **head,record_key_t *p)
{
	record_t *temp;
	temp=find_hash(*head,p);

	HASH_DEL(*head,temp);

	free(temp);
}
int count_hash(record_t *head)
{
	int num=0;
	num=HASH_COUNT(head);
	return num;
}

int main()
{
	record_t *head=NULL;

	record_t *r=NULL;

	r=(record_t*)malloc(sizeof(record_t));
	
	memset(r,0,sizeof(record_t));
	
	
	char *p="nimeia";               
        r->packet=p;

	r->key.saddr=1;
	r->key.daddr=2;
	r->key.source_port=3;
	r->key.dest_port=4;
	r->key.protocol=5;
	
	add_hash(&head,r);




	record_key_t *n;
		
	n=(record_key_t *)malloc(sizeof(record_key_t));

	memset(n,0,sizeof(record_key_t));
          
	n->saddr=1;
	n->daddr=2;
	n->source_port=3;
	n->dest_port=4;
	n->protocol=5;
	
	record_t *nimei;

	nimei=find_hash(head,n);
	printf("%s\n",nimei->packet);

	return 0;
}
